# -*- coding: utf-8 -*-
"""
# @Time    : 2021/1/12 下午3:15
# @Author  : tgy
"""


class Person:
    ...
    __name = ''
    __age = 0

    def __init__(self,name,age):
        ...
        self.__name = name
        self.__age = age

    # python3中property的用法，@property修饰的方法代表的是一个getter方法
    @property
    def name(self):
        return self.__name

    @name.setter
    def name(self, name):
        self.__name = name

    @name.deleter
    def name(self):
        raise PermissionError('can not del name')

    def run(self):
        print('person run')

    def __set_age(self,age):
        self.__age = age

    def __get_age(self):
        return self.__age

    def __del_age(self):
        raise PermissionError('can not del age')

    # python2 中 property的用法
    age = property(__get_age, __set_age, __del_age)

    def __str__(self):

        return f'car[name:{self.name},age:{self.age}]'


if __name__ == '__main__':
    ...
    person = Person('zhangsan', 23)
    print(person.__dict__)
    person.name = 'lisi'
    print(person.name)
    person.age = 20
    print(person.age)
